home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-03-18 | 1.9 KB | 86 lines | [TEXT/EDIT] |
- {$R-}
-
- (*
- ReplaceStr.p -- An XFNC which uses the Munger (the all-purpose trap!)
-
- Usage:
- put ReplaceStr <Source Containter> <Target Str> <Replacement Str>
- into <Destination Container>
-
- Return Value:
- The <Source Container>, with all instances of <Target Str>
- found in the <Source Container> replaced by <Replacement Str>
- No recursive replacement is tried, nor is the <Source Container>
- effected.
-
- Copyright © 1989 by D. Jay Newman. All rights reserved.
- *)
-
- {$S ReplaceStr } {Segment name must be the same as the command name.}
-
- UNIT DummyUnit;
-
- INTERFACE
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
-
- PROCEDURE EntryPoint (paramPtr: XCmdPtr);
-
- IMPLEMENTATION
-
- TYPE Str31 = String[31];
-
- PROCEDURE ReplaceStr (paramPtr: XCmdPtr); FORWARD; {So it can be called}
-
- PROCEDURE EntryPoint (paramPtr: XCmdPtr);
- BEGIN
- ReplaceStr (paramPtr);
- END;
-
- PROCEDURE ReplaceStr (paramPtr: XCmdPtr);
- VAR
- h: Handle; {Handle to Source text}
- offset: LONGINT;
- p: Ptr; {Pointer to calculate length}
- len1: LONGINT; {Length of target string}
- len2: LONGINT; {Length of replacement string}
- anErr: OSErr; {Result of HandToHand}
-
- {$I XCmdGlue.inc }
-
- BEGIN
- WITH paramPtr^ DO
- BEGIN
- IF paramCount <> 3 THEN EXIT (ReplaceStr); {Need all three params}
-
- h := params [1];
-
- HLock (params[2]); {Lock to avoid mem moves}
- p := params[2]^;
- ScanToZero (p);
- len1 := Ord4 (p) - Ord4 (params[2]^);
-
- HLock (params[3]); {Lock to avoid mem moves}
- p := params[3]^;
- ScanToZero (p);
- len2 := Ord4 (p) - Ord4 (params[3]^);
-
- offset := 0;
- WHILE offset >= 0 DO
- BEGIN
- offset := Munger (h, offset, params[2]^, len1,
- params[3]^, len2);
- END;
-
- HUnlock (params[2]); {Unlock like good boys}
- HUnlock (params[3]);
-
- anErr := HandToHand (h);
- IF anErr <> noErr THEN
- SysBeep (1);
-
- returnValue := h;
- END;
- END;
-
- END.